﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.ViewModel;
using System.Windows.Input;
using StudentModule.Commands;
using System.Windows;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Infrastructure.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Infrastructure.Helpers;

namespace StudentModule.ViewModels
{
    /// <summary>
    /// ViewModel for StudentManagerMenuView.
    /// </summary>
    public class StudentManagerMenuViewModel : NotificationObject
    {

        #region Fields
        IEventAggregator eventAggregator;
        IUnityContainer container;
        IRegionManager regionManager;
        bool isChinhSua;
        bool isNhapLieu;
        
        
        // Property variables
        #endregion

        #region Constructor
        /// <summary>
        /// Default constructor.
        /// </summary>
        public StudentManagerMenuViewModel(IEventAggregator eventAggregator, IRegionManager regionManager, IUnityContainer container)
        {
            this.container = container;
            this.eventAggregator = eventAggregator;
            this.regionManager = regionManager;
            this.Initialize();
        }
        #endregion

        #region Command Properties
        public ICommand ShowSearchSinhVienViewCommand { get; set; }
        public ICommand ShowBasicSearchSinhVienViewCommand { get; set; }
        public ICommand ShowImportSinhVienViewCommand { get; set; }
        public ICommand ShowImportHinhAnhViewCommand { get; set; }
        public ICommand ShowImportVanBangViewCommand { get; set; }

        #endregion

        #region Administrative Properties
        public IRegionManager RegionManager
        {
            get { return regionManager; }
        }

        public IEventAggregator EventAggregator
        {
            get { return eventAggregator; }
        }

        public IUnityContainer Container
        {
            get { return container; }
        }

        public bool IsChinhSua
        {
            get { return isChinhSua; }
            set { isChinhSua = value;
            RaisePropertyChanged(() => this.IsChinhSua);
            }
        }

        public bool IsNhapLieu
        {
            get { return isNhapLieu; }
            set { isNhapLieu = value;
            RaisePropertyChanged(() => this.IsNhapLieu);
            }
        }
        #endregion

        #region Event Handlers

        #endregion

        #region Private Methods
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        private void Initialize()
        {
            // Initialize the UI properties
            this.ShowSearchSinhVienViewCommand = container.Resolve<ShowSearchSinhVienViewCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<ShowSearchSinhVienViewCommand>()
            );

            this.ShowBasicSearchSinhVienViewCommand = container.Resolve<ShowBasicSearchSinhVienViewCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<ShowBasicSearchSinhVienViewCommand>()
            );

            this.ShowImportSinhVienViewCommand = container.Resolve<ShowImportSinhVienViewCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<ShowImportSinhVienViewCommand>()
            );

            this.ShowImportHinhAnhViewCommand = container.Resolve<ShowImportHinhAnhViewCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<ShowImportHinhAnhViewCommand>()
            );

            this.ShowImportVanBangViewCommand = container.Resolve<ShowImportVanBangViewCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<ShowImportVanBangViewCommand>()
            );

            IsChinhSua = PermissionChecker.HasQuyenChinhSuaThongTinSinhVien();
            IsNhapLieu = PermissionChecker.HasQuyenNhapLieu();
        }
        #endregion
    }
}
